<template>
    <div>
        <scroller
            :on-refresh="refresh"
            :on-infinite="infinite"
            ref="infinite"
        >
            <div class="cont">
                <div
                    v-for="(item, index) in listSource"
                    :key="index"
                >
                    <div>{{item.keywords}}</div>
                    <div>{{time(item.create_time,"yyyy-MM-dd hh:mm")}}</div>
                </div>
            </div>
        </scroller>
        <div style="height:50px;"></div>
        <Footer :idx="2" />
    </div>
</template>
<script>
import { formatDate } from "../../lib/time.js";
import Footer from '../../component/Footer'
export default {
    name: "find",
    data() {
        return {
            page: 1,
            limit: 10,
            listSource: []
        };
    },
    methods: {
        time(time, type) {
            let date = new Date(time);
            return formatDate(date, type);
        },
        infinite() {
            setTimeout(() => {
                this.getCrollerData();
            },
                500);
        },
        refresh() {
            this.page = 1;
            this.getCrollerData(true);
        },
        getCrollerData(type) {
            let params = {
                create_user: localStorage.getItem('token'),
                page: this.page,
                limit: this.limit
            };
            this.$post("/message/get_list", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.page++;
                        if (type) {
                            this.listSource = res.data.list;
                            setTimeout(() => {
                                this.$refs.infinite.finishPullToRefresh();
                            },
                                500);
                        } else {
                            for (let i in res.data.list) {
                                let newData = res.data.list[i];
                                this.listSource.push(newData);
                            }
                            if (res.data.list.length < this.limit) {
                                this.noData = false;
                                this.$refs.infinite.finishInfinite(true);
                            } else {
                                this.$refs.infinite.finishInfinite();
                            }
                        }
                    }
                })
                .catch(err => { });
        },
    },
    beforeCreate() {
        document.querySelector("body").setAttribute("style", "background-color:#e1deff");
    },
    created() { },
    components: {
        'Footer': Footer,
    },
};
</script>
<style lang="less" scoped>
@import url("../../asset/css/news");
</style>